package com.sh15tech.mp.weixin.job;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.jdbc.core.JdbcTemplate;

import com.sh15tech.gravity.quartz.job.GravityJob;
import com.sh15tech.mp.weixin.modal.WxMessage;
import com.sh15tech.mp.weixin.scan.WxSender;

public class RemindJob extends GravityJob {

	private Logger log = LogManager.getLogger(getClass());
	
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		
		String jobName = context.getJobDetail().getKey().getName();

		JobDataMap dataMap = context.getJobDetail().getJobDataMap();
		
		log.info(jobName+" start");
		
		WxMessage msg = (WxMessage)dataMap.get("message");
		JdbcTemplate jdbcTemplate = (JdbcTemplate)dataMap.get("jdbcTemplate");
		
		WxSender.enrollment(msg);
		
		jdbcTemplate.update("update t_wx_message t set t.msg_state = 1 where t.id="+msg.getId());
		
		log.info(jobName+" end");
		
	}
	
}
